use ffmpeg_sys_next::{
    AVPixelFormat, SwsContext, SwsFilter, sws_freeContext, sws_getContext, sws_scale,
};
use std::ffi::c_int;

pub fn sws_get_context_safe(
    src_w: c_int,
    src_h: c_int,
    src_format: AVPixelFormat,
    dst_w: c_int,
    dst_h: c_int,
    dst_format: AVPixelFormat,
    flags: c_int,
    src_filter: *mut SwsFilter,
    dst_filter: *mut SwsFilter,
    param: *const f64,
) -> *mut SwsContext {
    unsafe {
        sws_getContext(
            src_w, src_h, src_format, dst_w, dst_h, dst_format, flags, src_filter, dst_filter, param,
        )
    }
}

pub fn sws_scale_safe(
    c: *mut SwsContext,
    src_slice: *const *const u8,
    src_stride: *const c_int,
    src_slice_y: c_int,
    src_slice_h: c_int,
    dst: *const *mut u8,
    dst_stride: *const c_int,
) -> c_int {
    unsafe { sws_scale(c, src_slice, src_stride, src_slice_y, src_slice_h, dst, dst_stride) }
}

pub fn sws_free_context_safe(sws_context: *mut SwsContext) {
    unsafe { sws_freeContext(sws_context) }
}
